package com.kgc.onlineLife.service.impl;

import com.kgc.onlineLife.bean.Category;
import com.kgc.onlineLife.bean.Product;
import com.kgc.onlineLife.mapper.CategoryMapper;
import com.kgc.onlineLife.mapper.CustomerMapper;
import com.kgc.onlineLife.mapper.DashboardMapper;
import com.kgc.onlineLife.mapper.ProductMapper;
import com.kgc.onlineLife.service.ForeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * Created On : 2022/4/15.
 * <p>
 * Author     : 张冲
 * <p>
 * Description: ForeServiceImpl
 */
@Service
public class ForeServiceImpl implements ForeService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private DashboardMapper dashboardMapper;

    @Autowired
    private CustomerMapper customerMapper;

    /**
     * @author : 张冲
     * @date   : 2022/4/16
     * @param  : []
     * @return : java.util.List<com.kgc.onlineLife.bean.Category>
     * @description : 随机生成要展示的类型6选4
     */
    @Override
    public List<Category> listToFour() {
        List<Integer> list = new ArrayList<>();
        Random random = new Random();
        while(list.size()<4){
            int num = random.nextInt(6)+1;
            if (!list.contains(num)){
                list.add(num);
            }

        }
        List<Category> categoryList = new ArrayList<>();
        for(Integer cid:list){
           Category category = categoryMapper.selectCategories(cid);
           categoryList.add(category);
        }

        return categoryList;
    }

    @Override
    public List<Product> randProductFive() {
        List<Integer> list = new ArrayList<>();
        Random random = new Random();
        while(list.size()<5){
            int num = random.nextInt(30)+1;
            if (!list.contains(num)){
                list.add(num);
            }
        }
        List<Product> productList = new ArrayList<>();
        for(Integer id:list){
            Product product = productMapper.getProductDetail(id);
            productList.add(product);
        }
        return productList;
    }

    @Override
    public double TotalIncome1() {
        return dashboardMapper.totalIncome1();
    }

    @Override
    public double TotalIncome2() {
        return dashboardMapper.totalIncome2();
    }

    @Override
    public double TotalIncome3() {
        return dashboardMapper.totalIncome3();
    }

    @Override
    public double TotalIncome4() {
        return dashboardMapper.totalIncome4();
    }

    @Override
    public double TotalIncome5() {
        return dashboardMapper.totalIncome5();
    }

    @Override
    public double TotalIncome6() {
        return dashboardMapper.totalIncome6();
    }

    @Override
    public double TotalIncome7() {
        return dashboardMapper.totalIncome7();
    }


    @Override
    public Integer todayOrder() {
        return dashboardMapper.totalOrders();
    }

    @Override
    public Integer TotalCustomer() {
        return dashboardMapper.totalCustomers();
    }

    @Override
    public Integer TotalComment() {
        return dashboardMapper.totalComments();
    }

    @Override
    public Date getday1() {
        return dashboardMapper.getDay1();
    }

    @Override
    public Date getday2() {
        return dashboardMapper.getDay2();
    }

    @Override
    public Date getday3() {
        return dashboardMapper.getDay3();
    }

    @Override
    public Date getday4() {
        return dashboardMapper.getDay4();
    }

    @Override
    public Date getday5() {
        return dashboardMapper.getDay5();
    }

    @Override
    public Date getday6() {
        return dashboardMapper.getDay6();
    }

    @Override
    public Date getday7() {
        return dashboardMapper.getDay7();
    }

    @Override
    public Integer orderCount1() {
        return dashboardMapper.getOrderCount1();
    }

    @Override
    public Integer orderCount2() {
        return dashboardMapper.getOrderCount2();
    }

    @Override
    public Integer orderCount3() {
        return dashboardMapper.getOrderCount3();
    }

    @Override
    public Integer orderCount4() {
        return dashboardMapper.getOrderCount4();
    }

    @Override
    public Integer orderCount5() {
        return dashboardMapper.getOrderCount5();
    }

    @Override
    public Integer orderCount6() {
        return dashboardMapper.getOrderCount6();
    }

    @Override
    public Integer orderCount7() {
        return dashboardMapper.getOrderCount7();
    }

    @Override
    public List<Product> selectCollection(Integer cid) {
        return customerMapper.selectProductCollection(cid);
    }

    @Override
    public Integer selectTotalCollection(Integer cid) {
        return customerMapper.getTotalCollection(cid);
    }

    @Override
    public boolean insertIntoCollection(Integer cid, Integer pid) {
        return customerMapper.insertCollection(cid,pid)>0;
    }

    @Override
    public boolean insertIntofootPrint(Integer cid, Integer pid) {
        return customerMapper.insertFootPrint(cid,pid)>0;
    }

    @Override
    public Integer selectTotalFootPrint(Integer cid) {
        return customerMapper.getTotalFootPrint(cid);
    }

    @Override
    public List<Product> selectFootPrint(Integer cid) {
        return customerMapper.selectProductFootPrint(cid);
    }

    @Override
    public List<Integer> selectCollectionId(Integer cid, Integer pid) {
        return customerMapper.selectCollectionId(cid,pid);
    }

    @Override
    public boolean deleteCollection(List<Integer> ids) {
        return customerMapper.deleteCollection(ids)>0;
    }
}
